﻿using System.Drawing;
using CloudShot.Core.Utils;

namespace CloudShot.Core.Types
{
  /// <summary>
  ///   Represents information about taken screenshot.
  /// </summary>
  public sealed class ShotInfo
  {
    /// <summary>
    ///   Thumbnail size in pixels.
    /// </summary>
    private const int THUMB_SIZE = 48;

    /// <summary>
    ///   Gets or sets name of the screenshot.
    /// </summary>
    public string Name { get; set; }

    /// <summary>
    ///   Gets or sets path/link to the screenshot file.
    /// </summary>
    public string Path { get; set; }

    /// <summary>
    ///   Gets a thumbnail for the screenshot.
    /// </summary>
    public Image Thumbnail { get; private set; }

    /// <summary>
    ///   Creates instance of <see cref="ShotInfo" /> class.
    /// </summary>
    public ShotInfo() {}

    /// <summary>
    ///   Creates instance of <see cref="ShotInfo" /> class.
    /// </summary>
    /// <param name="name">A name of the <see cref="screenshot" />.</param>
    /// <param name="path">A path or link to the screenshot file.</param>
    /// <param name="screenshot">A screenshot taken from screen.</param>
    public ShotInfo(string name, string path, Image screenshot)
    {
      Name = name;
      Path = path;
      SetThumbnail(screenshot);
    }

    /// <summary>
    ///   Sets <see cref="Thumbnail" /> for the screenshot.
    /// </summary>
    /// <param name="screenshot">The screenshot <see cref="Image" />.</param>
    /// <remarks>
    ///   Before set the <see cref="Thumbnail" /> will be automatically resized to <see cref="THUMB_SIZE" />, if it is needed.
    /// </remarks>
    public void SetThumbnail(Image screenshot)
    {
      if (screenshot.Width <= THUMB_SIZE && screenshot.Height <= THUMB_SIZE)
        Thumbnail = screenshot;

      Thumbnail = ImgResizer.FixedSize(screenshot, THUMB_SIZE, THUMB_SIZE, Color.White);
    }
  }
}